﻿using AppService.IService.System_order;
using Domain.Entity.Basic_information;
using Domain.Entity.Order_goods;
using Domain.Entity.System_dictionary;
using Domain.Entity.System_operation;
using Domain.Entity.System_Ordermanagement;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Reflection.Metadata.Ecma335;

namespace WebAPI.Controllers.Order
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
        private readonly IorderService iorderService;

        public OrderController(IorderService IorderService)
        {
            iorderService = IorderService;
        }

        /// <summary>
        /// 查询订单表的数据总数
        /// </summary>
        /// <param name="Ord_state"></param>
        /// <param name="Ord_startaddress"></param>
        /// <param name="Ord_destination"></param>
        /// <param name="Ord_time"></param>
        /// <param name="Client_name"></param>
        /// <returns></returns>
        [HttpGet("{Ord_state}")]
        public int Count(int Ord_state, string? Ord_startaddress, string? Ord_destination, string? Ord_time, string? Client_name)
        {
            return iorderService.Count(Ord_state, Ord_startaddress, Ord_destination, Ord_time, Client_name);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public List<Orders> GetOrders(int currentPage, int PageSize)
        {
            List<Orders> orders = iorderService.GetOrders(currentPage, PageSize);
            return orders;
        }

        /// <summary>
        /// 根据订单状态查询
        /// </summary>
        /// <param name="state"></param>
        /// <param name="currentPage"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public List<Orders> GetOrder_state(int state, int currentPage, int PageSize)
        {
            return iorderService.GetOrders_state(state, currentPage, PageSize);
        }
        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="Ord_type"></param>
        /// <param name="Ord_startaddress"></param>
        /// <param name="Ord_destination"></param>
        /// <param name="Client_name"></param>
        /// <param name="Ord_time"></param>
        /// <returns></returns>
        [HttpGet]
        public List<Orders> GetOrders_condition(string Ord_type, string Ord_startaddress, string Ord_destination, string Client_name, string Ord_time)
        {
            //return iorderService.GetOrders_condition(Ord_type, Ord_startaddress, Ord_destination, Client_name,Ord_time);
            List<Orders> orders = new List<Orders>();
            return orders;
        }

        /// <summary>
        /// 查询数据字典，取运输类型的值（运输类型==订单类型）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Sys_dict_data> GetSys_Dict_Datas()
        {
            return iorderService.GetSys_dict_data();
        }

        /// <summary>
        /// 条件查询订单表（order）
        /// </summary>
        /// <param name="Ord_state"></param>
        /// <param name="Ord_startaddress"></param>
        /// <param name="Ord_destination"></param>
        /// <param name="Ord_time"></param>
        /// <param name="Client_name"></param>
        /// <param name="currentPage"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public List<Orders> GetOrders_conditions(int Ord_state, string? Ord_startaddress, string? Ord_destination, string? Ord_time, string? Client_name, int currentPage, int PageSize)
        {
            return iorderService.Orders_condition(Ord_state, Ord_startaddress, Ord_destination, Ord_time, Client_name, currentPage, PageSize);
        }

        /// <summary>
        /// 根据订单号查询客户表和订单表
        /// </summary>
        /// <param name="Ord_number"></param>
        /// <returns></returns>
        [HttpGet]
        public List<Order_client> GetOrder_Clients(string Ord_number)
        {
            return iorderService.GetOrder_client(Ord_number);
        }

        /// <summary>
        /// 查询订单货物表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Order_good_cargo> GetOgc(string Ord_number)
        {
            return iorderService.GetOgc(Ord_number);
        }

        /// <summary>
        /// 查询全部承运商
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Carrier_ment> GetCarrier_Ments()
        {
            return iorderService.GetCarrier_Ments();
        }

        /// <summary>
        /// 根据承运商查询司机
        /// </summary>
        /// <param name="Dv_carrier"></param>
        /// <returns></returns>
        [HttpGet("{Dv_carrier}")]
        public List<Drivers_ment> GetDrivers_Ments(int Dv_carrier)
        {
            return iorderService.GetDrivers_Ments(Dv_carrier);
        }

        /// <summary>
        /// 根据id查询司机
        /// </summary>
        /// <param name="Dv_id"></param>
        /// <returns></returns>
        [HttpGet("{Dv_id}")]
        public List<Drivers_ment> GetDrivers_Ments_id(int Dv_id)
        {
            return iorderService.GetDrivers_Ments_id(Dv_id);
        }

        /// <summary>
        /// 根据司机id查询车牌号
        /// </summary>
        /// <param name="Dv_id"></param>
        /// <returns></returns>
        [HttpGet("{Dv_id}")]
        public List<Vehicles_ment> GetVehicles_Ments(int Dv_id)
        {
            return iorderService.Getvehicles_Ments(Dv_id);
        }

        /// <summary>
        /// 根据车长和车型id查询数据字典车长和车型
        /// </summary>
        /// <param name="Dv_model"></param>
        /// <param name="Dv_length"></param>
        /// <returns></returns>
        [HttpGet("{Dv_model},{Dv_length}")]
        public List<Sys_dict_data> Get_Dict_Datas(int Dv_model, int Dv_length)
        {
            return iorderService.sys_Dict_Datas(Dv_model, Dv_length);
        }

        /// <summary>
        /// 查询订单货物
        /// </summary>
        /// <param name="Ord_id"></param>
        /// <returns></returns>
        [HttpGet("{Ord_id}")]
        public List<Order_cargo> GetOrder_Cargos(int Ord_id)
        {
            return iorderService.Getorder_Cargos(Ord_id);
        }

        /// <summary>
        /// 调度添加运单
        /// </summary>
        /// <param name="wb_Meter"></param>
        /// <returns></returns>
        [HttpPost]
        public bool Add([FromBody] Wb_meter? wb_Meter)
        {
            return iorderService.Add(wb_Meter);
        }

        /// <summary>
        /// 查询货物表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Cargo_ment> GetCargo_Ments()
        {
            return iorderService.GetCargo_Ments();
        }

        /// <summary>
        /// 查询客户户表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Customer_ment> GetCustomer_Ments()
        {
            return iorderService.GetCustomer_Ments();
        }

        /// <summary>
        /// 根据客户名称查询
        /// </summary>
        /// <param name="Ct_name"></param>
        /// <returns></returns>
        [HttpGet("{Ct_name}")]
        public List<Customer_ment> customer_Ments_name(string Ct_name)
        {
            return iorderService.GetCustomer_Ments_name(Ct_name);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="orders"></param>
        /// <returns></returns>
        [HttpPost]
        public bool Add2([FromBody] Orders orders)
        {
            return iorderService.AddOr(orders);
        }

        /// <summary>
        /// 根据订单编号查询
        /// </summary>
        /// <param name="Ord_number"></param>
        /// <returns></returns>
        [HttpGet("{Ord_number}")]
        public List<Orders> GetOrders_number(string Ord_number)
        {
            return iorderService.GetOrders_number(Ord_number);
        }

        /// <summary>
        /// 添加订单货物表
        /// </summary>
        /// <param name="order_Good"></param>
        /// <returns></returns>
        [HttpPost]
        public bool GetOrders_number([FromBody] Order_good order_Good)
        {
            return iorderService.AddOrders_good(order_Good);
        }

        [HttpPut("{Ord_id}")]
        public bool JD(int Ord_id)
        {
            return iorderService.JD(Ord_id);
        }

        [HttpPut("{Ord_id}")]
        public bool TH(int Ord_id)
        {
            return iorderService.TH(Ord_id);
        }

        [HttpPut("{Ord_id}")]
        public bool FC(int Ord_id)
        {
            return iorderService.FC(Ord_id);
        }

        [HttpPut("{Ord_id}")]
        public bool DZ(int Ord_id)
        {
            return iorderService.DZ(Ord_id);
        }

        [HttpPut("{Ord_id}")]
        public bool HD(int Ord_id)
        {
            return iorderService.HD(Ord_id);
        }
    }
}
